<template>
	<view>
		<view class="g-goBack" @click="toBack()">
			<view class="cuIcon-back"></view>
		</view>
		<view style="height: 100rpx;"></view>
		<view class="select">
			<text class="cuIcon-calendar"></text>
			<view @click="isOpenDate=true,current=1" :class="date1?'active':''" style="width: 30%;">
				{{date1?date1:'选择开始时间'}}
			</view>
			<text class="active">-</text>
			<view @click="isOpenDate=true,current=2" :class="date2?'active':''" style="width: 30%;">
				{{date2?date2:'选择结束时间'}}
			</view>
		</view>
		<view class="button" @click="submit">确定</view>
		<tmt-calendar defaultDate="2023-03-15" v-if="isOpenDate"  @changeDate="btnChange"></tmt-calendar>
		<view class="note">
			<view>* 请选择开始时间和结束时间</view>
			<view>* 开始时间必须小于或等于结束时间</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isOpenDate:false,
				current:1,
				date1:null,
				date2:null,
			}
		},
		methods: {
			btnChange(e){
				// console.log(e)
				const timeStr = e.year+'-'+e.month+'-'+e.day;
				if(this.current==1){
					this.date1 = timeStr;
				}else{
					this.date2 = timeStr;
				}
				this.isOpenDate = false;
			},
			submit(){
				this.isOpenDate = false;
				if(!this.date1||!this.date2){
					uni.showToast({
						title:'请选择时间',
						icon:'none'
					})
					return;
				}
				if(new Date(this.date1).getTime()>new Date(this.date2).getTime()){
					uni.showToast({
						title:'开始时间不能比结束时间更晚！',
						icon:'none'
					})
					return;
				}
				this.toBack();
			},
			toBack(){
				uni.redirectTo({
					url:`/pages/order/cdcz/list?start=${this.date1}&end=${this.date2}`
				})
			}
		}
	}
</script>

<style lang="less">
	.select{
		width: 90%;
		height: 80rpx;
		border-radius: 10rpx;
		border: 1rpx solid #e95d37;
		margin: 0 auto;
		padding: 0 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #999999;
		text-align: center;
		.active{
			color: #333333;
		}
	}
	.button{
		width: 90%;
		margin: 40rpx auto;
		background:linear-gradient(90deg,#f4b349,#ec7136);
		color: white;
		text-align: center;
		padding: 16rpx;
		border-radius: 10rpx;
		&.disable{
			background: linear-gradient(90deg,#d0d0d0,#999999);
		}
	}
	.note{
		width: 90%;
		margin: 40rpx auto;
		color: #999999;
	}
</style>
